package com.raymond.sgip.codec.decoding;

import com.raymond.client.codec.decoding.BaseDecoder;
import com.raymond.client.msg.BaseAgreement;
import com.raymond.sgip.msg.BaseSgipAgreement;
import com.raymond.sgip.msg.BaseSgipResponseMessage;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

/**
 * @author :  raymond
 * @version :  V1.0
 * @date :  2022-11-11 10:27
 */
public abstract class BaseSgipDecoder extends BaseDecoder {
    @Override
    public void decode(ChannelHandlerContext ctx, BaseAgreement msg, List<Object> out) throws Exception {
        decode0(ctx, msg, out);
        BaseSgipAgreement agreement = (BaseSgipAgreement)msg;
        BaseSgipResponseMessage responseMessage = (BaseSgipResponseMessage) out.get(0);
        responseMessage.setGateId(agreement.getGateId());
        responseMessage.setTimeStamp(agreement.getTimeStamp());
    }

    /**
     * 解码器
     * @param ctx ctx
     * @param msg 请求体
     * @param out out
     */
    public abstract void decode0(ChannelHandlerContext ctx, BaseAgreement msg, List<Object> out);
}
